package com.yunxi.service.localService.sys.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yunxi.bizToBaseData.pojo.AttachReqVO;
import com.yunxi.core.service.ServiceImplPlus;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.dao.sys.AttachMapper;
import com.yunxi.model.sys.SysAttach;
import com.yunxi.service.localService.sys.AttachService;
import com.yunxi.sys.pojo.AttachVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author caoYong
 * @since 2019-05-07
 */
@Service
public class AttachServiceImpl extends ServiceImplPlus<AttachMapper, SysAttach> implements AttachService {

   @Override
   public List<SysAttach> findAll(String pageNum, String pageSize){
      if(pageNum == null){
         pageNum = "0";
      }
      if(pageSize == null){
         pageSize = "10";
      }
      PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));

      return baseMapper.findAll();
   }

   @Override
   public PageInfo findPageByVO(AttachVO attachVO, Integer pageNum, Integer pageSize) {
      PageInfo pageInfo = pageByVo(attachVO, pageNum, pageSize);
      return pageInfo;
   }

   @Override
   public void saveByAttachVoList(List<AttachVO> attachVOList,String busId,String busSubId,LoginInfo login) {
      if(attachVOList!=null&&attachVOList.size()>0){
         baseMapper.delByBusSubId(busId,busSubId);
         for (int i=0;i<attachVOList.size();i++){
            AttachVO attachVO = attachVOList.get(i);
            SysAttach sysAttach = new SysAttach();
            attachVO.setBusId(busId);
            attachVO.setBusSubId(busSubId);
            attachVO.setCreateBy(login.getUserId());
            BeanUtils.copyProperties(attachVO, sysAttach);
            saveOrUpdate(sysAttach);
         }
      }
   }

   @Override
   public void saveByAttachReqVoList(List<AttachReqVO> attachVOList, String busId, String busSubId, LoginInfo loginInfo) {
      if(attachVOList!=null&&attachVOList.size()>0){
         for (int i=0;i<attachVOList.size();i++){
            AttachReqVO attachVO = attachVOList.get(i);
            SysAttach sysAttach = new SysAttach();
            attachVO.setBusId(busId);
            attachVO.setBusSubId(busSubId);
            attachVO.setCreateBy(loginInfo.getUserId());
            BeanUtils.copyProperties(attachVO, sysAttach);
            saveOrUpdate(sysAttach);
         }
      }
   }

   @Override
   public void delByBusSubId(String busId,String partnerCode) {
      baseMapper.delByBusSubId(busId,partnerCode);
   }
}
